
class Character
  attr_reader :realm, :name, :level, :last_modified, :thumbnail, :race, :achievement_points, :gender, :class_, :guild, :titles
  def initialize(realm, name, level, last_modified, thumbnail, race, achievement_points, gender, class_)
    @realm = realm
    @name = name
    @level = level
    @last_modified = last_modified
    @thumbnail = thumbnail
    @race = race
    @achievement_points = achievement_points
    @gender = gender
    @class_ = class_
    @guild = nil
    @titles = Array.new
  end

  def add_title(title)
    @titles << title
  end

  def add_guild(guild)
    @guild = guild
  end

  def to_s
    title = get_selected_title
    display_name = name
    display_name = title.sub_name(name) if title != nil
    "#{display_name} @ #{realm}"
  end

  def get_selected_title
    @titles.each { |title|
      return title if title.selected
    }
    nil
  end

  def get_gender
    if gender == 1
      "female"
    else
      "male"
    end
  end
end
